package sk.tuke.magsa.personalistika.ui;

import sk.tuke.magsa.framework.Utilities;
import sk.tuke.magsa.framework.ValidatorException;
import sk.tuke.magsa.framework.ui.FormDialog;
import sk.tuke.magsa.personalistika.entity.*;
import sk.tuke.magsa.personalistika.Application;

public class OddelenieForm extends FormDialog<Oddelenie>{
    public OddelenieForm() {
        super(new Oddelenie());
    }

    public OddelenieForm(Oddelenie entity) {
        super(entity);
    }

    public Oddelenie show() {
        String input;
        
        
        String nazov = entity.getNazov();
        do
        {
            try
            {
                System.out.print(String.format("Enter nazov [%s]: ", entity.getNazov()));
                input = Utilities.readLine();
                if(!"".equals(input))
                {
                    nazov = input;
                }
            
//-------------------------------Required-------------------------------
        if(nazov == null) {
             throw new ValidatorException("Property 'Nazov' is required!");
            }
            
//-------------------------------LENGTH-------------------------------
        if(nazov != null) {
            if( nazov.length() > 30 || nazov.length() < 5) {
                throw new ValidatorException("Property 'Nazov' has length out of range!");
            }
        }
                break;
            }
            catch(NumberFormatException e)
            {
                System.out.println("Cannot parse the entered value!");
            }
            catch(ValidatorException e)
            {
                System.out.println(e.getMessage());
            }
        }
        while(true);
        entity.setNazov(nazov);
        
        String kod = entity.getKod();
        do
        {
            try
            {
                System.out.print(String.format("Enter kod [%s]: ", entity.getKod()));
                input = Utilities.readLine();
                if(!"".equals(input))
                {
                    kod = input;
                }
            
//-------------------------------Required-------------------------------
        if(kod == null) {
             throw new ValidatorException("Property 'Kod' is required!");
            }
            
//-------------------------------LENGTH-------------------------------
        if(kod != null) {
            if( kod.length() > 4 || kod.length() < 1) {
                throw new ValidatorException("Property 'Kod' has length out of range!");
            }
        }
                break;
            }
            catch(NumberFormatException e)
            {
                System.out.println("Cannot parse the entered value!");
            }
            catch(ValidatorException e)
            {
                System.out.println(e.getMessage());
            }
        }
        while(true);
        entity.setKod(kod);
        
        Double uroven = entity.getUroven();
        do
        {
            try
            {
                System.out.print(String.format("Enter uroven [%s]: ", entity.getUroven()));
                input = Utilities.readLine();
                if(!"".equals(input))
                {
                    uroven = Double.valueOf(input);
                }
                break;
            }
            catch(NumberFormatException e)
            {
                System.out.println("Cannot parse the entered value!");
            }
            catch(ValidatorException e)
            {
                System.out.println(e.getMessage());
            }
        }
        while(true);
        entity.setUroven(uroven);





        return entity;
    }
}
